﻿using System;
using System.Linq;
using Oxage.CNC.Models;

namespace Oxage.Controls.AvalonEditExtensions
{
	public class GCodeSyntaxHighlighter : SyntaxHighlighterBase
	{
		public override string Name
		{
			get { return "G Code"; }
		}

		public override string[] FileExtensions
		{
			get { return new string[] { ".cnc" }; }
		}

		protected override string XshdPath
		{
			get { return "Resources/Syntax/Gcode.xshd"; }
		}

		public override bool IsBreakpointAllowed(string text)
		{
			var serializer = new GCodeSerializer();
			var obj = serializer.Deserialize(text);

			bool hasCode = false;
			foreach (var block in obj.Blocks)
			{
				foreach (var inline in block.Inlines.OfType<GCodeInline>())
				{
					if (!inline.IsComment)
					{
						hasCode = true;
						break;
					}
				}
			}

			return hasCode;
		}
	}
}
